from tkinter import *
import random as r

#创建根窗口
root = Tk()
root.title('登录界面')
root.geometry('300x200')

#账号
ID = Label(root,text='账号：')
ID.place(relx = 0.2,rely = 0.2,anchor=CENTER)#位置
text1 = Entry(root)
text1.place(relx=0.5, rely=0.2, anchor=CENTER,width = 150,height = 25)

#密码
password = Label(root, text='密码：')
password.place(relx=0.2, rely=0.4, anchor=CENTER)  # 位置
text2 = Entry(root)
text2.place(relx=0.5, rely=0.4, anchor=CENTER, width=150, height=25)

#验证码输入框
code = Label(root, text='验证码：')
code.place(relx=0.2, rely=0.6, anchor=CENTER)  # 位置
code = Entry(root)
code.place(relx=0.5, rely=0.6, anchor=CENTER, width=75, height=25)

#生成验证码
def createAuthcode():
    a = ''
    b = ''
    c = ''
    for i in range(2):
        num = r.randint(0,9)
        a += str(num)#数字
        num = r.randint(65,91)
        b += str(chr(num))#大写字母
        num = r.randint(97,123)
        c += str(chr(num))#小写字母
    string = str(a+b+c)
    txt.set(string)

#按钮
txt = StringVar()#字符串变量
txt.set("获取验证码")
codestr = Button(root, textvariable=txt, command=createAuthcode,fg='red', bg='green')
codestr.place(relx=0.8, rely=0.6, anchor=CENTER, width=75, height=25)

# def login():#待完善
#     if text1 == 'codemao' and text2 == '123456':
#         print('登录成功')
        #Tk().messagebox.showinfo(title = 'welcome',message = 'hello'+text1)

#登录按钮
enter = Button(root,text='登录')
enter.place(relx=0.5, rely=0.8, anchor=CENTER)

root.mainloop()
